package com.gun3y.entity.media;

import java.util.ArrayList;
import java.util.List;

import com.gun3y.entity.Wrapper;
import com.gun3y.entity.pattern.AttributePattern;
import com.gun3y.entity.pattern.FieldPattern;
import com.gun3y.entity.pattern.FieldPatternExpression;
import com.gun3y.entity.pattern.PositionPattern;
import com.gun3y.entity.pattern.TagPattern;

public enum WrapperObjectProps {
    hasFieldPattern {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof Wrapper && value != null && value instanceof FieldPattern) {
		Wrapper wrapper = (Wrapper) obj;
		List<FieldPattern> fields = wrapper.getFields();
		if (fields == null) {
		    fields = new ArrayList<FieldPattern>();
		    wrapper.setFields(fields);
		}

		fields.add((FieldPattern) value);
	    }
	}
    },

    hasPatternExpression {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof FieldPattern && value != null && value instanceof FieldPatternExpression) {
		FieldPattern fieldPattern = (FieldPattern) obj;
		List<FieldPatternExpression> list = fieldPattern.getExpressions();
		if (list == null) {
		    list = new ArrayList<FieldPatternExpression>();
		    fieldPattern.setExpressions(list);
		}

		list.add((FieldPatternExpression) value);
	    }
	}
    },

    hasPosition {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof FieldPattern && value != null && value instanceof PositionPattern) {
		FieldPattern fieldPattern = (FieldPattern) obj;
		fieldPattern.setPosition((PositionPattern) value);
	    }
	}
    },

    hasTag {
	@Override
	public void set(Object obj, Object value) {
	}
    },

    hasAttribute {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof TagPattern && value != null && value instanceof AttributePattern) {
		TagPattern tagPattern = (TagPattern) obj;
		List<AttributePattern> list = tagPattern.getAttributes();
		if (list == null) {
		    list = new ArrayList<AttributePattern>();
		    tagPattern.setAttributes(list);
		}

		list.add((AttributePattern) value);
	    }

	}
    },

    hasChildTag {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof PositionPattern && value != null && value instanceof TagPattern) {
		PositionPattern positionPattern = (PositionPattern) obj;
		positionPattern.setChildPattern((TagPattern) value);
	    }
	}
    },

    hasLocalTag {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof PositionPattern && value != null && value instanceof TagPattern) {
		PositionPattern positionPattern = (PositionPattern) obj;
		positionPattern.setLocalPattern((TagPattern) value);
	    }
	}
    },

    hasNextsiblingTag {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof PositionPattern && value != null && value instanceof TagPattern) {
		PositionPattern positionPattern = (PositionPattern) obj;
		positionPattern.setNextSiblingPattern((TagPattern) value);
	    }
	}
    },

    hasParentTag {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof PositionPattern && value != null && value instanceof TagPattern) {
		PositionPattern positionPattern = (PositionPattern) obj;
		positionPattern.setParentPattern((TagPattern) value);
	    }
	}
    },

    hasPresiblingTag {
	@Override
	public void set(Object obj, Object value) {
	    if (obj != null && obj instanceof PositionPattern && value != null && value instanceof TagPattern) {
		PositionPattern positionPattern = (PositionPattern) obj;
		positionPattern.setPreSiblingPattern((TagPattern) value);
	    }
	}
    };

    public abstract void set(Object obj, Object value);
}
